package com.lagou.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("toLogin")
    public String to_login(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("跳转到登录页面");
        return "login";
    }

    @RequestMapping("login")
    public String login(String username,
                        String password,
                        HttpSession httpSession) {
        System.out.println("用户登录操作");
        // 用户验证成功，保存信息到session
        if ("admin".equals(username) && "admin".equals(password)) {
            System.out.println("用户验证通过");
            httpSession.setAttribute("username", username);
            return "redirect:/resume/list";
        }else {
            // 验证不通过，跳转到登录页面
            System.out.println("验证不通过");
            return "redirect:/user/toLogin";
        }
    }
}
